package com.ruoyi.web.controller.addController;

import com.fasterxml.jackson.databind.ser.std.StdArraySerializers;
import com.ruoyi.web.model.AppResult;
import com.ruoyi.web.model.Dashboard;
import com.ruoyi.web.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class DashboardController {
    @Autowired
    private DashboardService dashboardService;
    @RequestMapping("/sys/dashboard")
    public AppResult<Dashboard> dashboard() {
        Dashboard dashboard = new Dashboard();
        dashboard.setArticleCount(dashboardService.getArticleCount());
        dashboard.setUserCount(dashboardService.getUserCount());
        dashboard.setMessageCount(dashboardService.getMessageCount());
        dashboard.setVisitCount(dashboardService.getVisitCount());
        dashboard.setContributionData(dashboardService.getContributionData());
        return AppResult.success(dashboard);
    }

    @RequestMapping("/sys/dashboard/bottom")
    public AppResult<List<Map<String, Integer>>> getBottomData() {
        return AppResult.success(dashboardService.getBottomData());
    }

    // 浏览趋势接口
    @RequestMapping("/sys/dashboard/browse-trend")
    public AppResult<List<Integer>> getBrowseTrendData(@RequestParam(required = false, defaultValue = "month") String period) {
        Integer days = period.equals("month") ? 30 : 7;
        List<Integer> browseTrendData = dashboardService.getBrowseTrendData(days);
        return AppResult.success(browseTrendData);
    }

}
